package com.ruipengkj.model;

import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.ruipengkj.bean.TWorkShift;


/**
 * 说明：交班记录查询Model
 * 
 * @Author：孙航
 */
public class WorkShiftModel extends AbstractTableModel {

	private static final long serialVersionUID = 1L;
	private Vector<List<Object>> rowdatas = new Vector<List<Object>>();
	private Vector<String> columns = new Vector<String>();

	public WorkShiftModel() {
		columns.add("交班记录ID");
		columns.add("本班员工");
		columns.add("交班时间");
//		columns.add("交班员工");
//		columns.add("交接金额");
		columns.add("交班总收入");
		columns.add("系统记录总消费次数");
		columns.add("系统记录订单会员卡消费总金额");
		columns.add("系统记录订单优惠券金额");
		columns.add("系统记录会员卡充值金额");
		columns.add("系统记录其他现金收入");
//		columns.add("客户端ID");
		columns.add("状态");
	}

	@Override
	public Class<?> getColumnClass(int columnIndex) {
		switch(columnIndex) {
		case 7:
		case 8:
			return Double.class;
		}
		return super.getColumnClass(columnIndex);
	}

	// 获得行数
	public int getRowCount() {
		return rowdatas.size();
	}

	// 获得列数
	public int getColumnCount() {
		return columns.size();
	}

	// 获得单元格的值
	@SuppressWarnings("unchecked")
	public Object getValueAt(int row, int column) {
		return ((Vector) rowdatas.get(row)).get(column);
	}

	// 获取列名
	public String getColumnName(int column) {
		return (String) columns.get(column);
	}

	// 设置单元格是否可编辑
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return false;
	}

	public void removeData(int row) {
		rowdatas.remove(row);
	}

	// 设置单元格的值
	@SuppressWarnings("unchecked")
	public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
		// 取出对应的记录
		Vector rowdata = (Vector) rowdatas.get(rowIndex);
		// 删除原来的值
		rowdata.remove(columnIndex);
		// 添加用户新修改的值
		rowdata.add(columnIndex, aValue);
	}

	public void setRowData(List<TWorkShift> TWorkShiftList) {
		rowdatas.clear();
		if (TWorkShiftList != null && TWorkShiftList.size() != 0) {
			for (int i = 0; i < TWorkShiftList.size(); i++) {
				TWorkShift tWorkShift = TWorkShiftList.get(i);
				List<Object> row = new Vector<Object>();
				row.add(tWorkShift.getWorkShiftID());
				row.add(tWorkShift.getToEmployeeID());
				row.add(tWorkShift.getHappenTime());
//				row.add(tWorkShift.getUpEmployeeID());
//				row.add(tWorkShift.getUpAmount());
				row.add(tWorkShift.getSTotalIncome());
				row.add(tWorkShift.getSOrderCount());
				row.add(tWorkShift.getSOrderCardAmount());
				row.add(tWorkShift.getSOrderCachCardAmount());
				row.add(tWorkShift.getSCardRechangeAmount());
				row.add(tWorkShift.getSOtherCashAmount());
//				row.add(tWorkShift.getClientID());
				if(tWorkShift.getStatus()==2){
					row.add("已交班");
				}else{
					row.add("未交班");
				}
				
				rowdatas.add(row);
			}
		}
	}
}
